/**
*  \file can_ext_rx.c
*
*  \brief External CAN receive function
*
*  \author dajin.li  <dajin.li@linde-china.cn>
*
*/

/*===============================================[ private includes  ]================================================*/
#include "can_ext_rx.h"
#include "cancom.h"
#include "../assertor/assertor.h"
#include "../pal/pal_mem.h"
#include "../endian/endian_read.h"
#include "../nth/nth.h"
#include "../saturated/sinc.h"
#include "../sched/sched.h"
#include "../can/can.h"
#include "../endian/endian.h"
#include "../kwpservices/kwpservices.h"
#include "../app/app.h"


/*===============================================[ private defines   ]================================================*/

/*MotorL PDO1 0x18E*/
#define   L_StatorCurrent_s16        can_ext_rx.signal.motor_lift_rx_pdo1.store.motorl_statorCurrent
#define   L_AliveCount_b4            can_ext_rx.signal.motor_lift_rx_pdo1.store.motorl_active_cnt
#define   L_ChipTemp_s8              can_ext_rx.signal.motor_lift_rx_pdo1.store.motorl_chip_temp
#define   L_ConvReady_b1             can_ext_rx.signal.motor_lift_rx_pdo1.store.motorl_conv_ready
#define   L_MagnReady_b1             can_ext_rx.signal.motor_lift_rx_pdo1.store.motorl_Magn_ready
#define   L_MotorTemp_s8             can_ext_rx.signal.motor_lift_rx_pdo1.store.motorl_motor_temp
#define   L_NoError_b2               can_ext_rx.signal.motor_lift_rx_pdo1.store.motorl_no_error
#define   L_NoHwEnable_b1            can_ext_rx.signal.motor_lift_rx_pdo1.store.motorl_no_hw_enable
#define   L_NoPwmSet_b1              can_ext_rx.signal.motor_lift_rx_pdo1.store.motorl_no_pwm_set
#define   L_NoSwEnable_b1            can_ext_rx.signal.motor_lift_rx_pdo1.store.motorl_no_sw_enable
#define   L_NoPwmStat_b1             can_ext_rx.signal.motor_lift_rx_pdo1.store.motorl_no_pwm_stat
#define   L_Vl2_dm1_b1               can_ext_rx.signal.motor_lift_rx_pdo1.store.motorl_vl2_dm1
#define   L_Vl2_dm2_b1               can_ext_rx.signal.motor_lift_rx_pdo1.store.motorl_vl2_dm2 
#define   L_Vl2_dm3_b1               can_ext_rx.signal.motor_lift_rx_pdo1.store.motorl_vl2_dm3 
#define   L_Vl2_dm4_b1               can_ext_rx.signal.motor_lift_rx_pdo1.store.motorl_vl2_dm4 
#define   L_statorFreq_s16           can_ext_rx.signal.motor_lift_rx_pdo1.store.motorl_statorFreq 


/*MotorL PDO2 0x28E*/
#define   L_EstBatCurr_s16           can_ext_rx.signal.motor_lift_rx_pdo2.store.lift_est_bat_current
#define   L_EstTorque_s16            can_ext_rx.signal.motor_lift_rx_pdo2.store.lift_est_torque
#define   L_MeasSpeed_s16            can_ext_rx.signal.motor_lift_rx_pdo2.store.lift_measure_speed
#define   L_PwmRatio_u16             can_ext_rx.signal.motor_lift_rx_pdo2.store.lift_pwmRatio

/*MotorL PDO3 0x38E*/
#define   L_MotorPump_DTC1_u16       can_ext_rx.signal.motor_lift_rx_pdo3.store.lift_dtc1
#define   L_MotorPump_DTC2_u16       can_ext_rx.signal.motor_lift_rx_pdo3.store.lift_dtc2
#define   L_MotorPump_DTC3_u16       can_ext_rx.signal.motor_lift_rx_pdo3.store.lift_dtc3
#define   L_MotorPump_DTC4_u16       can_ext_rx.signal.motor_lift_rx_pdo3.store.lift_dtc4

/*MotorT PDO1 0x18A*/
#define   T_AliveCount_Lft_b4        can_ext_rx.signal.motor_trac_rx_pdo1.store.trac_motorl_active_cnt
#define   T_ChipTemp_Lft_s8          can_ext_rx.signal.motor_trac_rx_pdo1.store.trac_chip_temp
#define   T_ConvReady_Lft_b1         can_ext_rx.signal.motor_trac_rx_pdo1.store.trac_motor_conv_ready
#define   T_MagnReady_Lft_b1         can_ext_rx.signal.motor_trac_rx_pdo1.store.trac_motorl_Magn_ready
#define   T_MotorTemp_Lft_s8         can_ext_rx.signal.motor_trac_rx_pdo1.store.trac_motorl_temp
#define   T_NoError_Lft_b2           can_ext_rx.signal.motor_trac_rx_pdo1.store.trac_motor_no_error
#define   T_NoHwEnable_Lft_b1        can_ext_rx.signal.motor_trac_rx_pdo1.store.trac_motor_no_hw_enable
#define   T_NoPwmSet_Lft_b1          can_ext_rx.signal.motor_trac_rx_pdo1.store.trac_motor_no_pwm_set
#define   T_NoSwEnable_Lft_b1        can_ext_rx.signal.motor_trac_rx_pdo1.store.trac_motor_no_sw_enable
#define   T_NoPwmStat_Lft_b1         can_ext_rx.signal.motor_trac_rx_pdo1.store.trac_motor_no_pwm_stat
#define   T_StatorCurrent_Lft_s16    can_ext_rx.signal.motor_trac_rx_pdo1.store.trac_stator_current_lft
#define   T_StatorFreq_Lft_s16       can_ext_rx.signal.motor_trac_rx_pdo1.store.trac_stator_freq_lft
#define   T_VT2_dm1_b1               can_ext_rx.signal.motor_trac_rx_pdo1.store.trac_vt2_dm1
#define   T_VT2_dm2_b1               can_ext_rx.signal.motor_trac_rx_pdo1.store.trac_vt2_dm2 
#define   T_VT2_dm3_b1               can_ext_rx.signal.motor_trac_rx_pdo1.store.trac_vt2_dm3 
#define   T_VT2_dm4_b1               can_ext_rx.signal.motor_trac_rx_pdo1.store.trac_vt2_dm4 

/*MotorT PDO2 0x28A*/
#define   T_EstBatCurr_Lft_s16       can_ext_rx.signal.motor_trac_rx_pdo2.store.trac_est_bat_current_lft
#define   T_EstTorque_Lft_s16        can_ext_rx.signal.motor_trac_rx_pdo2.store.trac_est_torque_lft
#define   T_MeasSpeed_Lft_s16        can_ext_rx.signal.motor_trac_rx_pdo2.store.trac_measure_speed_lft
#define   T_PwmRatio_Lft_s16         can_ext_rx.signal.motor_trac_rx_pdo2.store.trac_pwm_ration_lft

/*MotorT PDO3 0x38A*/
#define   MotorTrac_DTC1_u16         can_ext_rx.signal.motor_trac_rx_pdo3.store.trac_dtc1
#define   MotorTrac_DTC2_u16         can_ext_rx.signal.motor_trac_rx_pdo3.store.trac_dtc2
#define   MotorTrac_DTC3_u16         can_ext_rx.signal.motor_trac_rx_pdo3.store.trac_dtc3
#define   MotorTrac_DTC4_u16         can_ext_rx.signal.motor_trac_rx_pdo3.store.trac_dtc4

/*DebugV PDO0 0x625*/
#define   Vechicle_rx_debug0_0_u16   can_ext_rx.signal.debugv_rx_pdo0.store.debugv_dbg0_0
#define   Vechicle_rx_debug0_1_u16   can_ext_rx.signal.debugv_rx_pdo0.store.debugv_dbg0_1
#define   Vechicle_rx_debug0_2_u16   can_ext_rx.signal.debugv_rx_pdo0.store.debugv_dbg0_2
#define   Vechicle_rx_debug0_3_u16   can_ext_rx.signal.debugv_rx_pdo0.store.debugv_dbg0_3

/*Motor Heartbeat 0x70A*/
#define   MotorMcuState_en           can_ext_rx.signal.motor_state

/*Timestamp 0xff*/
#define   TimeStamp_u32              can_ext_rx.signal.timeStamp


#define EQU_SAC_PWM_FACTOR           (1.732f / 2.0F)//(sqrt(3) / 2.0F)


/*===============================================[ private datatypes ]================================================*/
struct can_ext_rx_signal
{
    enum command_type command;
    enum node_states motor_state;
    U32  timeStamp;
    union
    {
        U8  u8data[8];
        struct
        {
        	//U32 time_stamp_can;
        	//U32 dummy;               /* This will prevent errors if a can message with dlc>4 is received */
        }store;
    }timestamp_pdo;

    union
    {
        U8  u8data[8];
        struct
        {
            S16 motorl_statorCurrent;    /*Byte0:1 0 :15*/
            S8  motorl_motor_temp;       /*Byte2   16:23*/
            S8  motorl_chip_temp;        /*Byte3   24:31*/
            S16 motorl_statorFreq;       /*Byte4:5 32:39*/
            U8  motorl_no_error:2;       /*Byte6   48:49*/
            U8  motorl_conv_ready:1;     /*Byte6   50:50*/
            U8  motorl_no_pwm_stat:1;    /*Byte6   51:51*/
            U8  motorl_Magn_ready:1;     /*Byte6   52:52*/
            U8  motorl_no_hw_enable:1;   /*Byte6   53:53*/
            U8  motorl_no_sw_enable:1;   /*Byte6   54:54*/
            U8  motorl_vl2_dm4:1;        /*Byte6   55:55*/
            U8  motorl_no_pwm_set:1;     /*Byte7   56:56*/
            U8  motorl_vl2_dm1:1;        /*Byte7   57:57*/
            U8  motorl_vl2_dm2:1;        /*Byte7   58:58*/
            U8  motorl_vl2_dm3:1;        /*Byte7   59:59*/
            U8  motorl_active_cnt:4;     /*Byte7   60:63*/
        }store;
    }motor_lift_rx_pdo1;

    union
    {
        U8  u8data[8];
        struct
        {
            S16 lift_est_torque;        /*Byte0:1 0  :15*/
            S16 lift_measure_speed;     /*Byte2:3 16 :31*/
            S16 lift_est_bat_current;   /*Byte4:5 32 :47*/
            U16 lift_pwmRatio;          /*Byte5:6 48 :63*/
        }store;
    }motor_lift_rx_pdo2;

    union
    {
        U8  u8data[8];
        struct
        {
            U16 lift_dtc1;              /*Byte0:1 0  :15*/
            U16 lift_dtc2;              /*Byte2:3 16 :31*/
            U16 lift_dtc3;              /*Byte4:5 32 :47*/
            U16 lift_dtc4;              /*Byte6:7 48 :63*/
        }store;
    }motor_lift_rx_pdo3;

    union
    {
        U8  u8data[8];
        struct
        {
            S16 trac_stator_current_lft;                /*Byte0:1 0 :15*/
            S8  trac_motorl_temp;                       /*Byte2   16:23*/
            S8  trac_chip_temp;                         /*Byte3   24:31*/
            S16 trac_stator_freq_lft;                   /*Byte4:5 32:47*/
            U8  trac_motor_no_error:2;                  /*Byte6   48:49*/
            U8  trac_motor_conv_ready:1;                /*Byte6   50:50*/
            U8  trac_motor_no_pwm_stat:1;               /*Byte6   51:51*/
            U8  trac_motorl_Magn_ready:1;               /*Byte6   52:52*/
            U8  trac_motor_no_hw_enable:1;              /*Byte6   53:53*/
            U8  trac_motor_no_sw_enable:1;              /*Byte6   54:54*/
            U8  trac_vt2_dm4:1;                         /*Byte6   55:55*/
            U8  trac_motor_no_pwm_set:1;                /*Byte7   56:56*/
            U8  trac_vt2_dm1:1;                         /*Byte6   57:57*/
            U8  trac_vt2_dm2:1;                         /*Byte6   58:58*/
            U8  trac_vt2_dm3:1;                         /*Byte6   59:59*/
            U8  trac_motorl_active_cnt:4;               /*Byte7   60:63*/
        }store;
    }motor_trac_rx_pdo1;

    union
    {
        U8  u8data[8];
        struct
        {
            S16 trac_est_torque_lft;                    /*Byte0:1 0  :15*/
            S16 trac_measure_speed_lft;                 /*Byte2:3 16 :31*/
            S16 trac_est_bat_current_lft;               /*Byte4:5 32 :47*/
            S16 trac_pwm_ration_lft;                    /*Byte6   48 :55*/
        }store;
    }motor_trac_rx_pdo2;

    union
    {
        U8  u8data[8];
        struct
        {
            U16 trac_dtc1;                              /*Byte0:1 0  :15*/
            U16 trac_dtc2;                              /*Byte2:3 16 :31*/
            U16 trac_dtc3;                              /*Byte4:5 32 :47*/
            U16 trac_dtc4;                              /*Byte6:7 48 :63*/
        }store;
    }motor_trac_rx_pdo3;
    
    union
    {
        U8  u8data[8];
        struct
        {
            U16 debugv_dbg0_0;               /*Byte0:1 0  :15*/
            U16 debugv_dbg0_1;               /*Byte2:3 16 :31*/
            U16 debugv_dbg0_2;               /*Byte4:5 32 :47*/
            U16 debugv_dbg0_3;               /*Byte4:5 48 :63*/
        }store;
    }debugv_rx_pdo0;
    
};

/** Private variables */
struct can_ext_rx_private
{
   struct tasklet task_10ms;
   struct tasklet task_1ms;
   struct tasklet task_idle;
   struct can_ext_rx_signal signal;
};


/*===============================================[ private variables ]================================================*/



static struct can_ext_rx_private can_ext_rx;
/*===============================================[ public variables ]================================================*/




/*===============================================[ private functions ]================================================*/
static void can_ext_rx_process_motor_heartbeat(struct canmsg* msg, void *data );
static void can_ext_rx_process_timestamp(struct canmsg* msg, void *data );
static void can_ext_rx_process_motorl_pdo1(struct canmsg* msg, void *data );
static void can_ext_rx_process_motorl_pdo2(struct canmsg* msg, void *data );
static void can_ext_rx_process_motorl_pdo3(struct canmsg* msg, void *data );
static void can_ext_rx_process_motort_pdo1(struct canmsg* msg, void *data );
static void can_ext_rx_process_motort_pdo2(struct canmsg* msg, void *data );
static void can_ext_rx_process_motort_pdo3(struct canmsg* msg, void *data );

static void can_ext_rx_process_debug_pdo0(struct canmsg* msg, void *data );
static void can_ext_rx_10ms_service (struct tasklet *task);
static void can_ext_rx_1ms_service  (struct tasklet *task);
static void can_ext_rx_idle_service (struct tasklet *task);


/*================================================[ inline functions ]================================================*/

/*================================================[ public functions ]================================================*/
RC can_ext_rx_initialize( void )
{
   pal_memzero( &can_ext_rx,     sizeof can_ext_rx );

   tasklet_assign( sched_get_slice_10ms(), &can_ext_rx.task_10ms,  can_ext_rx_10ms_service, NIL );
   tasklet_assign( sched_get_slice_1ms(),  &can_ext_rx.task_1ms,   can_ext_rx_1ms_service,  NIL );
   tasklet_assign( sched_get_slice_idle(), &can_ext_rx.task_idle,  can_ext_rx_idle_service, NIL );

   can_install_rx_callback( can_channel_ext, Motor_Heartbeat_Rx,         can_ext_rx_process_motor_heartbeat,     (void*)&can_ext_rx.signal.motor_state );
   can_install_rx_callback( can_channel_ext, TimeStamp_Rx,               can_ext_rx_process_timestamp,           (void*)can_ext_rx.signal.timestamp_pdo.u8data );
   can_install_rx_callback( can_channel_ext, MotorL_PDO1_Rx,             can_ext_rx_process_motorl_pdo1,         (void*)can_ext_rx.signal.motor_lift_rx_pdo1.u8data );
   can_install_rx_callback( can_channel_ext, MotorL_PDO2_Rx,             can_ext_rx_process_motorl_pdo2,         (void*)can_ext_rx.signal.motor_lift_rx_pdo2.u8data );
   can_install_rx_callback( can_channel_ext, MotorL_PDO3_Rx,             can_ext_rx_process_motorl_pdo3,         (void*)can_ext_rx.signal.motor_lift_rx_pdo3.u8data );
   can_install_rx_callback( can_channel_ext, MotorT_PDO1_Rx,             can_ext_rx_process_motort_pdo1,         (void*)can_ext_rx.signal.motor_trac_rx_pdo1.u8data );
   can_install_rx_callback( can_channel_ext, MotorT_PDO2_Rx,             can_ext_rx_process_motort_pdo2,         (void*)can_ext_rx.signal.motor_trac_rx_pdo2.u8data );
   can_install_rx_callback( can_channel_ext, MotorT_PDO3_Rx,             can_ext_rx_process_motort_pdo3,         (void*)can_ext_rx.signal.motor_trac_rx_pdo3.u8data );
   can_install_rx_callback( can_channel_ext, DebugV_PDO0_Rx,             can_ext_rx_process_debug_pdo0,          (void*)can_ext_rx.signal.debugv_rx_pdo0.u8data );
   return RC_SUCCESS;
}


/*===============================================[ private functions ]================================================*/

/** 10ms Service function
*
*   \param task Pointer to calling tasklet.
*
*/
static void can_ext_rx_10ms_service (struct tasklet *task)
{
    UNREFERENCED( task );
}

/** 1ms Service function
*
*   \param task Pointer to calling tasklet.
*
*/
static void can_ext_rx_1ms_service (struct tasklet *task)
{
    UNREFERENCED( task );
}

/** Idle Service function
*
*   \param task Pointer to calling tasklet.
*
*/
static void can_ext_rx_idle_service (struct tasklet *task)
{
    UNREFERENCED( task );
}

/**
*  identifier:    0x70A
*  transmitter: Motor
*  transmission:  cyclically every 40 ms
*
*/
static void can_ext_rx_process_motor_heartbeat(struct canmsg* msg, void *data )
{
    U8 buf[2] = {0x01, 0x0A};
    pal_memcpy(data, canmsg_data_ptr(msg), canmsg_get_dlc(msg));

    if(can_ext_rx.signal.motor_state == pre_operational)
    {
        can_tx( can_channel_ext, canid_ext_module_control, buf,2);
    }
    else if(can_ext_rx.signal.motor_state == stopped)
    {
        buf[0] = enter_pre_operational;
        can_tx( can_channel_ext, canid_ext_module_control, buf,2);
    }
}

/**
*  identifier:    0x70A
*  transmitter: Motor
*  transmission:  cyclically every 40 ms
*
*/
static void can_ext_rx_process_timestamp(struct canmsg* msg, void *data )
{
    pal_memcpy(data, canmsg_data_ptr(msg), canmsg_get_dlc(msg));
	input_data.ba_DateTime_Can = TimeStamp_u32;
}


/**
*  identifier:    0x18E
*  transmitter:   motor lift
*  transmission:  cpu_m board sends every 10 ms
*  meaning: 
*
*/
static void can_ext_rx_process_motorl_pdo1(struct canmsg* msg, void *data )
{
    pal_memcpy(data, canmsg_data_ptr(msg), canmsg_get_dlc(msg));

    /* .. = b_L1_statorCurrent_b   ; */
    input_data.mE_TMot_Can   = (F32)L_MotorTemp_s8  + can_temper_min;
    input_data.mE_TMos_Can   = (F32)L_ChipTemp_s8 + can_temper_min;

    /* .. = b_L1_statorFreq_b      ; */
    input_data.mE_StsError_Can_1        =  L_NoError_b2 == 0x02 ? 0 : 1 ;
    input_data.mE_StsReady_Can        =  L_ConvReady_b1               ;
    input_data.mE_StsPwmOn_Can        =  L_NoPwmStat_b1               ;
    input_data.mE_StsMagnetized_Can   =  L_MagnReady_b1               ;
    input_data.mE_StsHwEnabled_Can    = !L_NoHwEnable_b1              ;
    input_data.mE_StsSwEnabled_Can    = !L_NoSwEnable_b1              ;
	input_data.mE_StsPwmSet_b1_can    = !L_NoPwmSet_b1                ;
    /* .. =  b_L1_ConvLocked_b     ; */
    /* .. =  b_L1_NoPwmSet_b       ; */
    input_data.mE_HBeatCnt_Can        =  (S16)L_AliveCount_b4         ;

    input_data.mE_statorCurrent_can   = L_StatorCurrent_s16;
    input_data.mE_statorFreq_can      = L_statorFreq_s16;
    input_data.mE_VL2_dm1             = L_Vl2_dm1_b1;
    input_data.mE_VL2_dm2             = L_Vl2_dm2_b1;
    input_data.mE_VL2_dm3             = L_Vl2_dm3_b1;
    input_data.mE_VL2_dm4             = L_Vl2_dm4_b1;
	
}
/**
*  identifier:    0x28E
*  transmitter:   motor lift
*  transmission:  cpu_m board sends every 10 ms
*  meaning: 
*
*/
static void can_ext_rx_process_motorl_pdo2(struct canmsg* msg, void *data )
{
    pal_memcpy(data, canmsg_data_ptr(msg), canmsg_get_dlc(msg));
    input_data.mE_mEval_Can  = ((F32)(S16)L_EstTorque_s16)   * can_resol_torque          ;
    input_data.mE_nSen_Can   = ((F32)(S16)L_MeasSpeed_s16)   * can_resol_rpm             ;
    input_data.mE_iBat_Can   = ((F32)(S16)L_EstBatCurr_s16)  * can_resol_current_drive   ;
	input_data.mE_lift_pwmRatio =(F32) L_PwmRatio_u16;
    /* .. =  b_L1_pwmRatio_b      ; */
}



/**
*  identifier:    0x38E
*  transmitter:   motor lift
*  transmission:  cpu_m board sends every 10 ms
*  meaning: 
*
*/
static void can_ext_rx_process_motorl_pdo3(struct canmsg* msg, void *data )
{
    pal_memcpy(data, canmsg_data_ptr(msg), canmsg_get_dlc(msg));
    input_data.mE_DTC_Can[0]  = L_MotorPump_DTC1_u16;
    input_data.mE_DTC_Can[1]  = L_MotorPump_DTC2_u16;
    input_data.mE_DTC_Can[2]  = L_MotorPump_DTC3_u16;
    input_data.mE_DTC_Can[3]  = L_MotorPump_DTC4_u16;
}

/**
*  identifier:    0x18A
*  transmitter:   motor traction
*  transmission:  cpu_m board sends every 10 ms
*  meaning: CANopen timestamp message for current time and date
*
*/
static void can_ext_rx_process_motort_pdo1(struct canmsg* msg, void *data )
{
	//u16 test_data;
    pal_memcpy(data, canmsg_data_ptr(msg), canmsg_get_dlc(msg));
    input_data.mL_HBeatCnt_Can      = T_AliveCount_Lft_b4;        
    input_data.mL_StsReady_Can      = T_ConvReady_Lft_b1;         
    input_data.mL_StsMagnetized_Can = T_MagnReady_Lft_b1;         
    input_data.mL_StsError_Can      = T_NoError_Lft_b2 == 0x02 ? 0 : 1 ;           
    input_data.mL_StsHwEnabled_Can  = !T_NoHwEnable_Lft_b1;        
    //test_data = T_NoPwmSet_Lft_b1;          
    input_data.mL_StsSwEnabled_Can  = !T_NoSwEnable_Lft_b1;        
    input_data.mL_StsPwmOn_Can      = T_NoPwmStat_Lft_b1;         
    input_data.mL_iMot_Can          = T_StatorCurrent_Lft_s16;
    input_data.mL_fqSta_Can         = T_StatorFreq_Lft_s16; 
    input_data.mL_TMos_Can          = T_ChipTemp_Lft_s8;
    input_data.mL_TMot_Can_1          = T_MotorTemp_Lft_s8;
    input_data.mL_StsNoPwmSet_Lft_b1_Can  = !T_NoPwmSet_Lft_b1;
	
    input_data.mL_vt2_dm1           = T_VT2_dm1_b1;
    input_data.mL_vt2_dm2           = T_VT2_dm2_b1;
    input_data.mL_vt2_dm3           = T_VT2_dm3_b1;
    input_data.mL_vt2_dm4           = T_VT2_dm4_b1;
}

/**
*  identifier:    0x28A
*  transmitter:   motor traction
*  transmission:  cpu_m board sends every 10 ms
*  meaning: 
*
*/
static void can_ext_rx_process_motort_pdo2(struct canmsg* msg, void *data )
{
    pal_memcpy(data, canmsg_data_ptr(msg), canmsg_get_dlc(msg));

    input_data.mL_mEval_Can  = ((F32)(S16)T_EstTorque_Lft_s16)  * can_resol_torque;
    input_data.mL_nSen_Can   = ((F32)(S16)T_MeasSpeed_Lft_s16)  * can_resol_rpm;
    input_data.mL_iBat_Can   = ((F32)(S16)T_EstBatCurr_Lft_s16) * can_resol_current_drive;
    input_data.mL_xSta_Can   = (F32)T_PwmRatio_Lft_s16 * can_resol_ratio;

    /* 29.09.2014/TW: SAC-PWM-Verhaeltnis um 1.15 zu hoch */
    input_data.mL_xSta_Can   *= (EQU_SAC_PWM_FACTOR);
}

/**
*  identifier:    0x38A
*  transmitter:   motor traction
*  transmission:  cpu_m board sends every 10 ms
*  meaning:
*
*/
static void can_ext_rx_process_motort_pdo3(struct canmsg* msg, void *data )
{
    pal_memcpy(data, canmsg_data_ptr(msg), canmsg_get_dlc(msg));
    
    input_data.mL_DTC_Can[0]  = MotorTrac_DTC1_u16;
    input_data.mL_DTC_Can[1]  = MotorTrac_DTC2_u16;
    input_data.mL_DTC_Can[2]  = MotorTrac_DTC3_u16;
    input_data.mL_DTC_Can[3]  = MotorTrac_DTC4_u16;
}

/**
*  identifier:    0x625
*  transmitter:   debug rx pdo0 
*  transmission:  not fixed
*  meaning: test data
*
*/
static void can_ext_rx_process_debug_pdo0(struct canmsg* msg, void *data )
{
    pal_memcpy(data, canmsg_data_ptr(msg), canmsg_get_dlc(msg));
    
    input_data.v_debug_rx_0[0]  = Vechicle_rx_debug0_0_u16;
    input_data.v_debug_rx_0[1]  = Vechicle_rx_debug0_1_u16;
    input_data.v_debug_rx_0[2]  = Vechicle_rx_debug0_2_u16;
    input_data.v_debug_rx_0[3]  = Vechicle_rx_debug0_3_u16;
}



/***********************************************************************************************************************
*                             Copyright 2018 Linde Material Handling. All rights reserved.                             *
***********************************************************************************************************************/
